package com.hwd.gmall.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hwd.gmall.common.util.MyThreadLocal;
import com.hwd.gmall.model.user.UserAddress;
import com.hwd.gmall.user.mapper.UserAddressMapper;
import com.hwd.gmall.user.service.UserAddressService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户收货地址信息管理的的接口实现类
 *
 * @author 黄伟东/Victor
 * @date 2022/5/4 21:48
 */
@Service
public class UserAddressServiceImpl implements UserAddressService {

    @Resource
    private UserAddressMapper userAddressMapper;

    /**
     * 根据用户名查询用户的收获地址信息
     *
     * @return java.util.List<com.hwd.gmall.model.user.UserAddress>
     */
    @Override
    public List<UserAddress> listUsersAddress() {
        // 从本地线程对象中获取用户名
        String username = MyThreadLocal.get();
        return userAddressMapper.selectList(
                new LambdaQueryWrapper<UserAddress>()
                        .eq(UserAddress::getUserId, username));
    }
}
